package com.ruoyi.ca.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ca.domain.CaJylsh;
import com.ruoyi.ca.service.ICaJylshService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 交易流水号信息Controller
 *
 * @author ruoyi
 * @date 2024-04-16
 */
@RestController
@RequestMapping("/ca/jylsh")
public class CaJylshController extends BaseController {
    @Autowired
    private ICaJylshService caJylshService;

    /**
     * 查询交易流水号信息列表
     */
    @PreAuthorize("@ss.hasPermi('ca:jylsh:list')")
    @GetMapping("/list")
    public TableDataInfo list(CaJylsh caJylsh) {
        startPage();
        List<CaJylsh> list = caJylshService.selectCaJylshList(caJylsh);
        return getDataTable(list);
    }

    /**
     * 导出交易流水号信息列表
     */
    @PreAuthorize("@ss.hasPermi('ca:jylsh:export')")
    @Log(title = "交易流水号信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CaJylsh caJylsh) {
        List<CaJylsh> list = caJylshService.selectCaJylshList(caJylsh);
        ExcelUtil<CaJylsh> util = new ExcelUtil<CaJylsh>(CaJylsh.class);
        util.exportExcel(response, list, "交易流水号信息数据");
    }

    /**
     * 获取交易流水号信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ca:jylsh:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(caJylshService.selectCaJylshById(id));
    }

    /**
     * 新增交易流水号信息
     */
    @PreAuthorize("@ss.hasPermi('ca:jylsh:add')")
    @Log(title = "交易流水号信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CaJylsh caJylsh) {
        return toAjax(caJylshService.insertCaJylsh(caJylsh));
    }

    /**
     * 修改交易流水号信息
     */
    @PreAuthorize("@ss.hasPermi('ca:jylsh:edit')")
    @Log(title = "交易流水号信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CaJylsh caJylsh) {
        return toAjax(caJylshService.updateCaJylsh(caJylsh));
    }

    /**
     * 删除交易流水号信息
     */
    @PreAuthorize("@ss.hasPermi('ca:jylsh:remove')")
    @Log(title = "交易流水号信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(caJylshService.deleteCaJylshByIds(ids));
    }

    @Log(title = "交易流水号信息导入", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('ca:jylsh:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) {
        if (null == file) {
            return AjaxResult.error("请选择要导入的文件！");
        }
        String name = file.getOriginalFilename();
        if (StringUtils.isEmpty(name) || (!name.endsWith("xls") && !name.endsWith("xlsx"))) {
            return AjaxResult.error("仅允许导入xls、xlsx格式文件。");
        }
        String operName = getUsername();
        String message = caJylshService.importCaJylsh(file, operName);
        return success(message);
    }
}
